package com.person.jc.web.buy;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.person.jc.service.buy.BsBuyApplyService;
import com.person.jc.service.buy.BsBuyLogService;
import com.person.jc.utils.DateUtils;
import com.person.jc.utils.Servlets;
import com.person.jc.utils.Utils;

public class BsBuyLogController extends Controller {
	
	public void init(){
		setAttr("menuId", getPara("menuId"));
		setAttr("startDate",DateUtils.formatDate(DateUtils.addMonths(new Date(), -1), "yyyy-MM-dd"));
		
		setAttr("endDate",DateUtils.getDate());
		render("main.jsp");
	}
	
	public void list(){
		Map<String, Object> map = Servlets.getParametersStartingWith(getRequest(), "p_");
		List<Record> list = BsBuyLogService.me.getList(map);
		setAttr("list", list);
		render("list.jsp");
	}
	
	public void edit(){
		String buyId = getPara("buyId");
		String view = getPara("view");
		if(Utils.isNotEmpty(buyId)){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("buyId", buyId);
			List<Record> list = BsBuyLogService.me.getList(map);
			if(list.size() != 0){
				setAttr("obj", list.get(0));
			}
			List<Record> details = BsBuyApplyService.me.getBuyDetail(buyId);
			setAttr("details", details);
		}
		setAttr("view", view);
		render("edit.jsp");
	}
	
}
